home *** CD-ROM | disk | FTP | other *** search
- Path: rcp6.elan.af.mil!rscernix!danpop
- From: danpop@mail.cern.ch (Dan Pop)
- Newsgroups: comp.lang.c
- Subject: Re: C constant expression declarations
- Date: 16 Feb 96 11:40:44 GMT
- Organization: CERN European Lab for Particle Physics
- Message-ID: <danpop.824470844@rscernix>
- References: <31229735.41C67EA6@isi.com> <DMto56.Lo3@uns.bris.ac.uk> <4fvm2hINNa61@keats.ugrad.cs.ubc.ca>
- NNTP-Posting-Host: ues5.cern.ch
- X-Newsreader: NN version 6.5.0 #7 (NOV)
-
- In <4fvm2hINNa61@keats.ugrad.cs.ubc.ca> c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku) writes:
-
- >In article <DMto56.Lo3@uns.bris.ac.uk>,
- >Nathan Sidwell <nathan@pact.srf.ac.uk> wrote:
- > >: ...and so on. Lately, I have been observing in code from other people
- > >: equivalent declarations such as:
- > >
- > >: #define EXPR1 (1)
- > >: #define EXPR2 (2)
- > >
- > >Whilst, as I'm sure you realise, it's necessary to put brackets round
- > >things like (a + b), it is not necessary around unsigned constants.
- > >However, a gotcha is using signed constants, for example
- > >
- > >#define EXPR -1
- > >if(a EXPR) ...
- >
- >Are you sure that C has signed constants? That is, is -1 lexically recognized
- >as a constant, or as a minus token followed by an integer quantity? It's
- >probably done the latter way, which means that "-1" is a compound expression.
- >If it weren't parsed this way, a construct like (a-1) would be parsed as
- >something like '(' IDENTIFIER INTEGER ')', a syntax error. I'm not sure what th
- >C standard says, just what common-sense about compiler construction says. :)
- >
- > >this will complile as 'a - 1', rather than give a syntax error
-
- This single line makes Kazimir's paragraph above completely pointless.
- Do people actually read the text they're commenting on?
-
- It's obvious (in context) that Nathan's "signed constants" was an
- unfortunate expression and he doesn't believe that C has signed constants.
-
- Dan
- --
- Dan Pop
- CERN, CN Division
- Email: danpop@mail.cern.ch
- Mail: CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
-